package com.zy1;

import com.zy1.mapper.EmpMapper;
import com.zy1.pojo.Emp;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Main {
    public static void main(String[] args) {
    String resource = "mybatis-config.xml";
        try {
            InputStream inputStream= Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession session = sqlSessionFactory.openSession();
            EmpMapper empMapper= session.getMapper(EmpMapper.class);
            List<Emp> emps = empMapper.selectAll();
            for (Emp emp : emps) {
                System.out.println(emp);
                }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}